#include "GameWorld.h"
#include "PeakValley/PeaksAndValleys.h"
#include "Utility/Utility.h"
#include "Camera/BaseCamera.h"
#include "Scene/Engine.h"
#include "GameApp.h"

CGameWorld::CGameWorld()
{

}

CGameWorld::~CGameWorld()
{
	UnInit();
}

void CGameWorld::Init()
{
	m_pCamera   = new CBaseCamera;

	float fViewWidth  = (float)GetApp()->GetEngine()->GetViewWidth();
	float fViewHeight = (float)GetApp()->GetEngine()->GetViewHeight();
	float fAspectRatio = fViewWidth / fViewHeight;
	m_pCamera->SetAspect(fAspectRatio);

	GameModule* pModule = new CPeaksAndValleysModule;
	pModule->Init();

	m_vecModules.push_back(pModule);
}

void CGameWorld::UnInit()
{
	for (UINT32 i = 0; i < m_vecModules.size();i++)
	{
		m_vecModules[i]->UnInit();
		SAFE_DELETE(m_vecModules[i]);
	}

	SAFE_DELETE(m_pCamera);
}

void CGameWorld::Update( float fTime )
{
	for (UINT32 i = 0; i < m_vecModules.size();i++)
	{
		m_vecModules[i]->Update(fTime);
	}
	
	m_pCamera->Update(fTime);
	GetApp()->GetEngine()->SetViewMatrix(m_pCamera->GetViewMatrix());
	GetApp()->GetEngine()->SetProjMatrix(m_pCamera->GetProjMatrix());

}

